package com.shop.cereshop.business.dl.logic.controller;

import com.shop.cereshop.business.dl.logic.domian.CareShopNewsForwardLogVo;
import com.shop.cereshop.business.dl.logic.domian.Result;
import com.shop.cereshop.business.dl.logic.service.CareShopNewsForwardLogService;
import com.shop.cereshop.business.dl.logic.service.SendPostImpl;
import com.shop.cereshop.business.dl.logic.service.TicketingImportService;
import com.shop.cereshop.business.dl.logic.utils.ResultInfo;
import com.shop.cereshop.business.service.product.CereShopProductService;
import com.shop.cereshop.commons.domain.business.CerePlatformBusiness;
import com.shop.cereshop.commons.domain.product.CereShopProduct;
import com.shop.cereshop.commons.exception.CoBusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @param
 * @description:DlProductsController
 * @return:
 * @author:作者:YF
 * @time:日期:2021/6/16 时间:9:46
 */
@Controller
@RequestMapping("/business")
@CrossOrigin
public class DlProductsController {

    @Autowired
    private SendPostImpl sendPost;
    @Autowired
    private CareShopNewsForwardLogService careShopNewsForwardLogService;
    @Autowired
    private TicketingImportService ticketingImportService;
    @Autowired
    private CereShopProductService cereShopProductService;

    /**
     * @param
     * @description:查询票务信息
     * @return:
     * @author:作者:YF
     * @time:日期:2021/6/15 时间:20:04
     */
    @PostMapping("/queryTickets")
    @ResponseBody
    public ResultInfo queryTickets(Integer pageIndex, Integer pageSize, @RequestParam(value = "productNo",required = false) String productNo, String sceneryNo, String productType) {
        String info = sendPost.GetProductInfo(1, 10, productNo, sceneryNo, productType);
        ResultInfo resultInfo = new ResultInfo();
        resultInfo.setData(info);
        return resultInfo;
    }

    /**
     * @param
     * @description:导入票务信息到数据库
     * @return:
     * @author:作者:YF
     * @time:日期:2021/6/15 时间:20:04
     */
    @PostMapping("/importTickets")
    @ResponseBody
    public ResultInfo importTickets(String productNo, HttpServletRequest request){
        //获取当前登录账户
        CerePlatformBusiness user = (CerePlatformBusiness) request.getAttribute("user");
        try {
            ticketingImportService.setShopProductAll(productNo, user);
            return ResultInfo.ok();
        } catch (CoBusinessException e) {
            e.printStackTrace();
            return ResultInfo.error(500,"存在未支付订单,无法导入");
        }
    }
//business/importTickets

    @PostMapping("/getNewsStatistics")
    @ResponseBody
    public ResultInfo<CareShopNewsForwardLogVo> getNewsStatistics(Integer newsId, @RequestParam(value = "page",defaultValue = "1") Integer page,
                                                                  @RequestParam(value = "row",defaultValue = "10") Integer row) {
        return careShopNewsForwardLogService.getNewsStatistics(newsId,page,row);
    }


    @GetMapping("/ConsumeNotice")
    @ResponseBody
    public Result ConsumeNotice(@RequestBody String requestHead, @RequestBody String requestBody){
      return sendPost.ConsumeNotice(requestHead,requestBody);
    }
    @PostMapping("/recommendedSettings2")
    @ResponseBody
    public ResultInfo recommendedSettings2(Integer productId,Integer sort){
        CereShopProduct c = cereShopProductService.selectById(productId);
        cereShopProductService.setRecommende2(productId,sort);
        return new ResultInfo();
    }
    //w设置分佣比例
    @PostMapping("/recommendedSettings3")
    @ResponseBody
    public ResultInfo recommendedSettings3(Integer productId,Integer commodityProportion){

        cereShopProductService.setRecommende3(productId,commodityProportion);
        return new ResultInfo();
    }

    @PostMapping("/recommendedSettings")
    @ResponseBody
    public ResultInfo recommendedSettings(Integer productId){
        CereShopProduct c = cereShopProductService.selectById(productId);
        String message = "";//1是推荐商品, 0是不推荐商品
        if (c.getRecommendedMark()==1){
            message = "取消推荐商品成功";
            c.setRecommendedMark(0);
        }else if (c.getRecommendedMark()==0){
            message = "设置推荐商品成功";
            c.setRecommendedMark(1);
        }
        cereShopProductService.setRecommende(c.getRecommendedMark(),productId);
        return new ResultInfo(200,message);
    }


    @GetMapping("/ConsumeNoticeTest")
    @ResponseBody
    public void ConsumeNoticeTest(){
        sendPost.ConsumeNoticeTest();
    }



}
